$dir="/data2/bsi/RandD/Arraybased_RND/tcga_genotyping";
$sdrf_dir="$dir/SRDF";
open(BUFF,"$dir/AFFY/files");
while(<BUFF>)
{
	chomp($_);
	if($_ ne "KIRC")
	{
		next;
	}
	print "$_ NORMAL\n";
	open(SAMP,"/data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37.tfam");
	open(INQC,"/data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/NORMAL/normal_all_merged_qc");
	open(OUTQC,">/data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/NORMAL/normal_all_merged_qc1");
	while($line=<SAMP>)
	{
        	chomp($line);
        	@a=split(' ',$line);
        	$hash{$a[1]}=1;
	}
	$line=<INQC>;
	chomp($line);
	if($line !~ m/YRI$/)
	{
		print OUTQC "$line\tEUR\tASN\tYRI\n";
	}
	while($line=<INQC>)
	{
        	chomp($line);
        	@a=split("\t",$line);
        	if(exists($hash{$a[0]}))
        	{
			$line=~ s/ /\t/g;
                	print OUTQC $line."\n";
        	}
	}
	system("mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/NORMAL/normal_all_merged_qc /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/NORMAL/old_qc_ignore");
	system("mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/NORMAL/normal_all_merged_qc1 /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/NORMAL/normal_all_merged_qc");
	print "$_ TUMOR\n";
        open(SAMP,"/data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37.tfam");
	open(INQC,"/data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/TUMOR/tumor_all_merged_qc");
        open(OUTQC,">/data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/TUMOR/tumor_all_merged_qc1");
	while($line=<SAMP>)
        {
                chomp($line);
                @a=split(' ',$line);
                $hash{$a[1]}=1;
        }
        $line=<INQC>;
        chomp($line);
	if($line !~ m/YRI$/)
	{
        print OUTQC "$line\tEUR\tASN\tYRI\n";
        }
	while($line=<INQC>)
        {
                chomp($line);
                @a=split("\t",$line);
                if(exists($hash{$a[0]}))
                {
                        $line=~ s/ /\t/g;
                        print OUTQC $line."\n";
                }
        }
	system("mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/TUMOR/tumor_all_merged_qc /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/TUMOR/old_qc_ignore");
	system("mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/TUMOR/tumor_all_merged_qc1 /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$_/TUMOR/tumor_all_merged_qc");

}
